function initPagination(totalItems,currentPage,itemsPerPage) {

    // Set parameters. These shold be passed in on init of the object
    var steps = 3;
    var stepsOutput = 0;
    var totalPages = totalItems / ITEMS_PER_PAGE;
    var edges = 2;
    var prevEllipse = false;
    var nextEllipse = false;

    //Empty pagination div
    $('.pagination-wrapper').empty();

    //Check if previous button is needed
    if (currentPage != 0) {
        $('.pagination-wrapper').append("<a class='prevLink'>Prev</a>");
    }

    //Display up to current
    for (i = 0; i < currentPage; i++) {
        if ((currentPage - i) <= steps && stepsOutput <= steps) {
            $('.pagination-wrapper').append("<a class='step'>" + (i + 1) + "</a>");
            stepsOutput++;
        }
        else if (i < edges) {
            $('.pagination-wrapper').append("<a class='step'>" + (i + 1) + "</a>");
        }

        else if (!prevEllipse) {
            $('.pagination-wrapper').append("<span class='step'>...</span>");
            prevEllipse = true;
        }

    }
    //Display  current
    $('.pagination-wrapper').append("<span class='currentStep'>" + (currentPage + 1) + "</span>");

    //Display  current to end
    for (i = currentPage + 1; i < totalPages; i++) {
        if ((i - currentPage) <= steps && stepsOutput <= steps) {
            $('.pagination-wrapper').append("<a class='step'>" + (i + 1) + "</a>");
            stepsOutput++;
        }
        else if (totalPages - i <= edges) {
            $('.pagination-wrapper').append("<a class='step'>" + (i + 1) + "</a>");
        }
        else if (!nextEllipse) {
            $('.pagination-wrapper').append("<span class='step'>...</span>");
            nextEllipse = true;
        }

    }
    //display next if applicable
    if (currentPage + 1 < totalPages) {
        $('.pagination-wrapper').append("<a class='nextLink'>Next</a>");
    }

    //set click handler for pagination links
    $(".pagination-wrapper a").click(function() {
        loadPage(this);
    });

    //show pagination div
    $(".pagination-wrapper").show();

}
